from aiogram import Dispatcher, types
from aiogram.filters import CommandStart
from aiogram_dialog import DialogManager, StartMode

from app.bot.keyboards.reply import menu
from app.database.requests import get_user_settings, create_user_settings


async def on_start_command(message: types.Message, dialog_manager: DialogManager):
    session = dialog_manager.middleware_data.get("session")
    if not await get_user_settings(session, message.from_user.id):
        await create_user_settings(session, message.from_user.id)
    else:
        await message.answer("Главное меню", reply_markup=menu())


def register_menu_handlers(dispatcher: Dispatcher):
    dispatcher.message.register(on_start_command, CommandStart())
